home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 6480 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.3 KB

  1. Path: news.netgate.net!news
  2. From: Tamara Johnson <malihini@netgate.net>
  3. Newsgroups: comp.lang.c
  4. Subject: Question - C (beginner)
  5. Date: Sat, 24 Feb 1996 17:23:29 -0800
  6. Organization: NetGate Communications
  7. Message-ID: <312FBA11.3946@netgate.net>
  8. NNTP-Posting-Host: d45.netgate.net
  9. Mime-Version: 1.0
  10. Content-Type: text/plain; charset=us-ascii
  11. Content-Transfer-Encoding: 7bit
  12. X-Mailer: Mozilla 2.0b6a (Win95; I)
  13.  
  14. Problem: not correctly counting chars in
  15. each word, not correctly counting words
  16. with >0 && <7 chars and words with >6 chars.
  17.  
  18. Suggestions greatly appreciated,
  19. Tamara
  20.  
  21. [stuff deleted - snippet?]
  22. {
  23. int i, cc, nl, nw, nc,inword;
  24.  
  25. inword=NO;
  26. cc=nl=nw=nc=0;
  27.  
  28.   for(i=0;i<n;i++)
  29.     {
  30.     nc++;
  31.     cc++;
  32.     if(test_string[i]=='\n')
  33.       nl++;
  34.     if(test_string[i]==' '||test_string[i]=='\n'
  35.        ||test_string[i]=='\0'||test_string[i]=='\t')
  36.       inword=NO;
  37.     else if(inword==NO)
  38.       {
  39.       inword=YES;
  40.       nw++;
  41.       if((cc>0)&&(cc<7)) under++;
  42.       if(cc>6) over++;
  43.       cc=0;
  44.       }
  45.     }
  46. }
  47.  
  48. /* -----output------- 
  49.  
  50. Enter test string: tickle something ugly
  51. Number of words in the string: 3
  52. Number of words with 7 or more char: 2
  53. Number of words with 6 or less char: 1
  54. */
  55. -- 
  56. /* malihini@netgate.net             */
  57. /* a.k.a. johnson_tamara@tandem.com */
  58. /* I used to think I knew logic,    */
  59. /* then I found C.                  */
  60.